package com.share.homestay.pojo;

import com.share.homestay.consts.ResultCode;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {
    /**
     * 返回码
     */
    private Integer code;
    /**
     *  返回消息
     */
    private String message;
    /**
     * 返回数据
     */
    private Object data;
    public Result(){


    }
    //自定义错误代码和错误信息
    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    //根据枚举固定错误代码获取
    public Result(ResultCode resultCode, Object data){
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;

    }
    /***
     *
     * @description: 操作成功不返回数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result success(){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.code());
        result.setMessage(ResultCode.SUCCESS.message());
        return result;
    }
    /***
     *
     * @description: 操作成功 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result success(Object data){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.code());
        result.setMessage(ResultCode.SUCCESS.message());
        result.setData(data);
        return result;

    }
    /***
     *
     * @description: 操作失败 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result failure(ResultCode resultCode){
        Result result = new Result();
        result.setCode(resultCode.code());
        result.setMessage(resultCode.message());
        return result;

    }
    /***
     *
     * @description: 操作失败 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result failure(Integer code, String message){
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;

    }
    /***
     *
     * @description: 操作成功 返回请求数据
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result failure(ResultCode resultCode,Object data){
        Result result = new Result();
        result.setCode(resultCode.code());
        result.setMessage(resultCode.message());
        result.setData(data);
        return result;

    }
    /***
     *
     * @description: 自定义返回码和返回信息
     * @Date: 2020/11/4 16:36
     * @return: com.currency.server.entity.response.Result
     **/
    public static Result custom(Integer code, String message, Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;

    }
}

